<?php
namespace Web\Controller;
class TagController extends CommonController {
    /**
     * 标签首页
     *
     * @param    void
     * @return    void
    **/
    public function index(){
        $tagid = I('get.id',0,'intval');
        verify($tagid,'notEmpty','标签ID不能为空');
        verify($tagid,'isNumber','非法标签ID');

        $tagInfo = M('Tags')->find($tagid);;
        verify($tagInfo,'notEmpty','标签不存在');

        $ArticleModel = D('Article');

        $p = I('get.p',1,'intval');

        $offset = ($p -1 ) * C('PER_PAGE_NUM');

        $where = array(
            'status'        =>  1,
            'sid'           =>  C('sid'),
            'publishtime'   =>  array('lt',NOW_TIME),
            'content'       =>  array('like','%'.$tagInfo['nickname'].'%')
        );

        $count  = $ArticleModel->where($where)->count();// 查询满足要求的总记录数

        if($count) {
            $list = $ArticleModel->limit($offset.','.C('PER_PAGE_NUM'))->where($where)->order('publishtime desc')->select();
        }else {
            $list = array();
        }

        $this->assign(array(
            'article_list'  =>  $list,
            'article_count' =>  $count,
            'tagid'         =>  $tagid,
            'tagInfo'       =>  $tagInfo
        ));
        $this->display();
    }
}
